<table id="admin_adminInfo_data"></table>
<script>
$(function(){
	$('#admin_adminInfo_data').datagrid({   
	    url:'../json/adminInfoAction_getAdminAll',
	    queryParams:{},
	    loadMsg:'数据加载中...',
	    pagination:true,
	    rownumbers:true,
	    fitColumns:true,
	  	sortName:'aid',
	  	sortOrder:'desc',
	  	remoteSort:false,
	    striped:true,
	    pageNumber:1,
	    pageSize:10, 
		pageList:[10,20,30,40,50],
	    columns:[[   
	    	{field:'pwd',title:'',checkbox:true,width:100,align:'center'}, 
	        {field:'aid',title:'管理员编号',width:100,align:'center',sortable:true},   
	        {field:'aname',title:'管理员姓名',width:100,align:'center'},   
	        {field:'pwds',title:'管理员密码',width:400,align:'center'},
	        {field:'statuss',title:'账号状态',width:100,align:'center'}   
	    ]],   
	    
	    toolbar: [{
	    	text:'添加',
			iconCls: 'icon-add',
			handler: function(){
				$("#admin_adminInfo_data_add").dialog("open");
			}
		},'-',{
			text:'删除',
			iconCls: 'icon-remove',
			handler: function(){
				//获取所有被选中的行
				var rows=$("#admin_adminInfo_data").datagrid("getChecked");
				if(rows.length<=0){  //说明没有选中
					$.messager.show({
						title:'温馨提示',
						msg:'请选择您要删除的数据...',
						timeout:2000,
						showType:'slide'
					});
				}else{
					$.messager.confirm('信息确认', '您确定要删除选中的信息吗？', function(r){
						if (r){
							var aids="";
							//获取所有选中的数据的id
							for(var i=0;i<rows.length-1;i++){
								aids+=rows[i].aid+",";
							}
							aids+=rows[i].aid;
							
							//向服务器发送请求
							$.post("../json/adminInfoAction_delAdminInfo",{aids:aids},function(data){
								data=parseInt( $.trim(data.result) );
								if(data>0){
								$.messager.show({
									title:'成功提示',
									msg:'管理员信息删除成功...',
									timeout:3000,
									showType:'slide'
								});
								$("#admin_adminInfo_data").datagrid("reload");
								}else{
									$.messager.alert('失败提示','管理员信息删除失败，请稍后再试...','error');
								}
							});
						}
					});
				}
			}
		},'-',{
			text:'修改',
			iconCls: 'icon-edit',
			handler: function(){
				var rows=$("#admin_adminInfo_data").datagrid("getChecked");
				if(rows.length<=0){
					$.messager.show({
						title:'温馨提示',
						msg:'请选择您要修改的数据...',
						timeout:2000,
						showType:'slide'
					});
				}else{
					$("#admin_adminName_update").val( rows[0].aname );
					$("#admin_adminPwd_update").val( rows[0].pwd );
					$("#admin_adminAid_update").val( rows[0].aid );
					$("#admin_adminInfo_data_update").dialog("open");
				}
			}
		}]
	});  
})

$("#admin_adminInfo_data").datagrid('getPager').pagination({
	beforePageText:'第',
	afterPageText:'页 共{pages}页',
	displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
})

//添加管理员信息
function admin_addInfo(){
	var aname=$.trim( $("#admin_adminName").val() );
	var pwd=$.trim( $("#admin_adminPwd").val() );
	
	//为空判断
	if(aname!="" && pwd!=""){
		$.post("../json/adminInfoAction_addAdminInfo",{"adminInfo.aname":aname,"adminInfo.pwd":pwd},function(data){
			data=parseInt( $.trim(data.result) );
			if(data>0){
				$.messager.show({
					title:'成功提示',
					msg:'管理员信息添加成功...',
					timeout:3000,
					showType:'slide'
				});
				$("#admin_adminName").val("");
				$("#admin_adminPwd").val("");
				$("#admin_adminInfo_data_add").dialog("close"); //关闭添加对话框
				$("#admin_adminInfo_data").datagrid("reload");
			}else{
				$.messager.alert('失败提示','管理员信息添加失败，请稍后再试...','error');
			}
		});
	}else{
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交...',
			timeout:3000,
		});
	}
}

//修该管理员信息
function admin_updateInfo(){
	var aname=$.trim( $("#admin_adminName_update").val() );
	var pwd=$.trim( $("#admin_adminPwd_update").val() );
	var aid=$.trim( $("#admin_adminAid_update").val() );
	
	$.post("../json/adminInfoAction_updateAdminInfo",{"adminInfo.aname":aname,"adminInfo.pwd":pwd,"adminInfo.aid":aid},function(data){
		data=parseInt( $.trim(data.result) );
		console.info(data);
		if(data>0){
			$.messager.show({
					title:'成功提示',
					msg:'管理员信息修改成功...',
					timeout:3000,
					showType:'slide'
				});
				$("#admin_adminName_update").val("");
				$("#admin_adminPwd_update").val("");
				$("#admin_adminInfo_data_update").dialog("close"); //关闭添加对话框
				$("#admin_adminInfo_data").datagrid("reload");
		}else{
			$.messager.alert('失败提示','管理员信息修改失败，请稍后再说...','error')
		}
	});
}
</script>

<div id="admin_adminInfo_data_add" class="easyui-dialog" title="添加管理员信息" style="width:400px;height:200px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    <br/>  <br/> 
    <center>
    	<label for="admin_adminName">管理员姓名：</label><input type="text" id="admin_adminName" />  <br/>  <br/> 
    	<label for="admin_adminPwd">管理员密码：</label><input type="password" id="admin_adminPwd" />  <br/>  <br/> 
   		<input type="button" onclick="admin_addInfo()" value="添加"/>
    </center>
</div>  

<div id="admin_adminInfo_data_update" class="easyui-dialog" title="修改管理员信息" style="width:400px;height:200px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    <br/>  <br/> 
    <center>
    	<input type="hidden" id="admin_adminAid_update" /> 
    	<label for="admin_adminName_update">管理员姓名：</label><input type="text" id="admin_adminName_update" />  <br/>  <br/> 
    	<label for="admin_adminPwd_update">管理员密码：</label><input type="password" id="admin_adminPwd_update" />  <br/>  <br/> 
   		<input type="button" onclick="admin_updateInfo()" value="修改"/>
    </center>
</div>  